package com.eascs.admin.o2o.data;

import java.util.ArrayList;
import java.util.List;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.common.util.StringUtil;
import com.eascs.common.util.UuidUtil;
import com.eascs.site.controller.BaseRestController;
import com.eascs.site.view.BaseRestResult;

@RestController
public class AutocompleteRestController extends BaseRestController {
	public final Logger logger = LoggerFactory.getLogger(AutocompleteRestController.class);

	@RequestMapping(value = "/o2o/data/autocomplete")
	public BaseRestResult<List<Object[]>> autocomplete(AutocompleteForm autocompleteForm) {
		List<Object[]> data = new ArrayList<>();
		if (StringUtil.hasText(autocompleteForm.getKey())) {
			data.add(new Object[] { UuidUtil.generateShortUuid(), autocompleteForm.getType() + autocompleteForm.getKey() + UuidUtil.generateShortUuid() });
			data.add(new Object[] { UuidUtil.generateShortUuid(), autocompleteForm.getType() + autocompleteForm.getKey() + UuidUtil.generateShortUuid() });
			data.add(new Object[] { UuidUtil.generateShortUuid(), autocompleteForm.getType() + autocompleteForm.getKey() + UuidUtil.generateShortUuid() });
			data.add(new Object[] { UuidUtil.generateShortUuid(), autocompleteForm.getType() + autocompleteForm.getKey() + UuidUtil.generateShortUuid() });
		}
		return BaseRestResult.buildRestResult(data);
	}

	@RequestMapping(value = "/o2o/data/autocomplete-desc")
	public BaseRestResult<List<Object[]>> autocompleteWithWDesc(AutocompleteForm autocompleteForm) {
		List<Object[]> data = new ArrayList<>();
		if (StringUtil.hasText(autocompleteForm.getKey())) {
			data.add(new Object[] { UuidUtil.generateShortUuid(), autocompleteForm.getType() + autocompleteForm.getKey() + UuidUtil.generateShortUuid(), "desc:" + autocompleteForm.getKey() + UuidUtil.generateShortUuid() });
			data.add(new Object[] { UuidUtil.generateShortUuid(), autocompleteForm.getType() + autocompleteForm.getKey() + UuidUtil.generateShortUuid(), "desc:" + autocompleteForm.getKey() + UuidUtil.generateShortUuid() });
			data.add(new Object[] { UuidUtil.generateShortUuid(), autocompleteForm.getType() + autocompleteForm.getKey() + UuidUtil.generateShortUuid(), "desc:" + autocompleteForm.getKey() + UuidUtil.generateShortUuid() });
		}
		return BaseRestResult.buildRestResult(data);
	}

}